--- title: fastproaudio core keywords: fastai sidebar: home_sidebar summary: "API details." description: "API details." nb_path: "00_core.ipynb" ---
Some audio data urls:
URLs.AUDIOMDPI = 'https://zenodo.org/record/3562442'
URLs.MARCO = URLs.AUDIOMDPI # just a shorthand alias I'm more likely to remember
URLs.SIGNALTRAIN_LA2A_1_1 = 'https://zenodo.org/record/3824876'
URLs.SIGNALTRAIN_LA2A_REDUCED = 'http://hedges.belmont.edu/data/SignalTrain_LA2A_Reduced.tgz'
print(URLs.MARCO)
print(zenodo_url_to_data_url(URLs.MARCO))
print(URLs.SIGNALTRAIN_LA2A_1_1)
print(zenodo_url_to_data_url(URLs.SIGNALTRAIN_LA2A_1_1))
Try downloading a sample .tgz file
path_st = get_audio_data(URLs.SIGNALTRAIN_LA2A_REDUCED)
path_st
And try downloading from a Zenodo URL:
path_audiomdpi = get_audio_data(URLs.MARCO)
path_audiomdpi
Let's use this data as an example and take a look at it:
path_audiomdpi.ls()
We'll grab the LeslieHorn subset
horn = path_audiomdpi / "LeslieHorn"; horn.ls()
path_dry = horn /'dry'
#path_trem = horn / 'tremolo'
audio_extensions = ['.m3u', '.ram', '.au', '.snd', '.mp3','.wav']
fnames_dry = get_files(path_dry, extensions=audio_extensions)
waveform, sample_rate = torchaudio.load(fnames_dry[0])
Let's take a look at it:
show_audio(waveform, sample_rate)
show_audio(waveform, sample_rate, info=False, play=False, plots=['melspec'], ref=1)
Let's make a multi-channel tensor and plot it:
num_channels = 5
n = waveform.shape[-1]*3
waveform2 = torch.zeros((num_channels,n))
for c in range(num_channels):
start = int(np.random.rand()*waveform.shape[-1]*(2))
this_waveform, _ = torchaudio.load(fnames_dry[c])
waveform2[c, start:start+waveform.shape[-1]] = this_waveform
show_audio(waveform2, sample_rate)
sample = waveform[0].numpy() # just simplify array dimensions for this demo
sample = sample[int(0.6*sample_rate):] # chop off the silence at the front for this demo
track_length = sample_rate*5
sample_len = sample.shape[-1]
target = np.zeros(track_length)
input = np.zeros(track_length)
click = np.zeros(track_length)
grid_interval = sample_rate
n_intervals = track_length // grid_interval
for i in range(n_intervals):
start = grid_interval*i
click[start] = 1 # click track
end = min( start+sample_len, track_length)
target[start:end] = sample[0:end-start] # paste the sample on the grid
# mess up the paste location
rand_start = max(0, start + np.random.randint(-grid_interval//2,grid_interval//2))
rand_end = min( rand_start+sample_len, track_length )
input[rand_start:rand_end] = sample[0:rand_end-rand_start]
fig = plt.figure(figsize=(14, 8))
plt.plot(target)
fig = plt.figure(figsize=(14, 8))
plt.plot(input)
fig = plt.figure(figsize=(14, 8))
plt.plot(click)